package com.example.playnote.retrofit

import com.example.playnote.bean.BannerResponse
import com.example.playnote.bean.FriendListResponse
import com.example.playnote.bean.HomeListResponse
import com.example.playnote.bean.HotKeyResponse
import com.example.playnote.bean.LoginResponse
import com.example.playnote.bean.TreeListResponse
import com.example.playnote.net.ApiResponse
import retrofit2.http.Field
import retrofit2.http.FormUrlEncoded
import retrofit2.http.GET
import retrofit2.http.POST
import retrofit2.http.Path
import retrofit2.http.Query

interface ApiService {
    @POST("user/login")
    suspend fun login(
        @Query("username") username: String,
        @Query("password") password: String
    ): ApiResponse<LoginResponse>

    @POST("user/register")
    suspend fun register(
        @Query("username") username: String,
        @Query("password") password: String,
        @Query("repassword") repassword: String = password
    ): ApiResponse<LoginResponse>

    @GET("banner/json")
    suspend fun getBanner(): ApiResponse<BannerResponse>


//    https://www.wanandroid.com/article/list/0/json
    @GET("article/list/{page}/json")
    suspend fun getHomeList(
        @Path("page") page: Int
    ): ApiResponse<HomeListResponse>

    /**
     * 收藏文章
     * @param id id
     * @return Deferred<HomeListResponse>
     */
    @POST("lg/collect/{id}/json")
    suspend fun addCollectArticle(
        @Path("id") id: Int
    ): ApiResponse<HomeListResponse>

    /**
     * 收藏站外文章
     * @param title title
     * @param author author
     * @param link link
     * @return Deferred<HomeListResponse>
     */
    @POST("lg/collect/add/json")
    @FormUrlEncoded
    suspend fun addCollectOutsideArticle(
        @Field("title") title: String,
        @Field("author") author: String,
        @Field("link") link: String
    ): ApiResponse<HomeListResponse>

    @GET("lg/collect/list/{page}/json")
    suspend fun getLikeList(
        @Path("page") page: Int
    ): ApiResponse<HomeListResponse>

    /**
     * 搜索
     * http://www.wanandroid.com/article/query/0/json
     * @param page page
     * @param k POST search key
     */
    @POST("article/query/{page}/json")
    @FormUrlEncoded
    suspend fun getSearchList(
        @Path("page") page: Int,
        @Field("k") k: String
    ): ApiResponse<HomeListResponse>
    /**
     * 知识体系
     * http://www.wanandroid.com/tree/json
     */
    @GET("tree/json")
    suspend fun getTypeTreeList(): ApiResponse<TreeListResponse>

    /**
     * 知识体系下的文章
     * http://www.wanandroid.com/article/list/0/json?cid=168
     * @param page page
     * @param cid cid
     */
    @GET("article/list/{page}/json")
    suspend fun getArticleList(
        @Path("page") page: Int,
        @Query("cid") cid: Int
    ): ApiResponse<HomeListResponse>

    /**
     * 我的常用网址
     * @return FriendListResponse
     */
    @GET("lg/collect/usertools/json")
    suspend fun getBookmarkList(): ApiResponse<FriendListResponse>

    /**
     * 常用网站
     * http://www.wanandroid.com/friend/json
     */
    @GET("friend/json")
    suspend fun getFriendList(): ApiResponse<FriendListResponse>

    /**
     * 大家都在搜
     * http://www.wanandroid.com/hotkey/json
     */
    @GET("hotkey/json")
    suspend fun getHotKeyList(): ApiResponse<HotKeyResponse>
}